﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YunSpace.Data;
using YunSpace.Domain.Entity.SystemManage;
using YunSpace.Domain.IRepository.SystemManage;
using YunSpace.Repository.SystemManage;

namespace YunSpace.Application.SystemManage
{
    public class SysAutoApp
    {
        private ISysAutoNoRepository autoRepository = new SysAutoNoRepository();
        public string CreateNumber() {
            string no = "";
            SysAutoNoEntity entity= autoRepository.FindList("select * from Sys_AutoNo").FirstOrDefault();
            using (var db = new RepositoryBase()) {
                if (entity == null)
                {
                    entity = new SysAutoNoEntity();
                    entity.Create();
                    entity.F_No = 1000;
                    db.Insert<SysAutoNoEntity>(entity);
                    no = "1000";
                }
                else {
                    entity.F_No = entity.F_No + 1;
                    entity.Modify(entity.F_Id);
                    db.Update<SysAutoNoEntity>(entity);
                    no = entity.F_No.ToString();
                }
            }
            return no;
        }
    }
}
